package com.crud.demo1.demos.controller;

import com.crud.demo1.demos.Service.ITFlowStepDefService;
import com.crud.demo1.demos.commons.AjaxResult;
import com.crud.demo1.demos.entity.TFlowStepDef;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangNing
 * @since 2025-02-27
 */
@Api(tags = "流程步骤定义")
@RestController
@RequestMapping("/tFlowStepDef")
public class TFlowStepDefController {

    private final ITFlowStepDefService iTFlowStepDefService;

    @Autowired
    public TFlowStepDefController(ITFlowStepDefService iTFlowStepDefService) {
        this.iTFlowStepDefService = iTFlowStepDefService;
    }

    @ApiOperation(value = "getFlowStepDef",notes = "列出所有流程步骤")
    @GetMapping("getFlowStepDef")
    public AjaxResult getFlowStepDef(){
        List<TFlowStepDef> flowStepDefList = iTFlowStepDefService.list();
        return AjaxResult.ok(flowStepDefList);
    }

    @ApiOperation(value = "addFlowStepDef",notes = "添加流程步骤")
    @PostMapping("addFlowStepDef")
    public AjaxResult addFlowStepDef(@RequestBody @Valid TFlowStepDef flowStepDef){
        boolean result = iTFlowStepDefService.save(flowStepDef);
        if(result){
            return AjaxResult.ok("添加成功");
        }
        return AjaxResult.fail("添加失败");
    }

    @ApiOperation(value = "updateFlowStepDef",notes = "修改流程步骤")
    @PostMapping("updateFlowStepDef")
    public AjaxResult updateFlowStepDef(@RequestBody @Valid TFlowStepDef flowStepDef){
       boolean result =  iTFlowStepDefService.updateById(flowStepDef);
       if(result){
           return AjaxResult.ok("修改成功");
       }
        return AjaxResult.fail("修改失败");
    }

    @ApiOperation(value = "delFlowStepDef",notes = "删除流程步骤")
    @RequestMapping(value = "delFlowStepDef",method = RequestMethod.DELETE)
    public AjaxResult delFlowStepDef(@RequestBody @Valid TFlowStepDef flowStepDef){
       boolean result = iTFlowStepDefService.removeById(flowStepDef);
       if(result){
           return AjaxResult.ok("删除成功");
       }
        return AjaxResult.fail("删除失败");
    }

}
